RouterOS auto-sys-restore is a user-created script for MikroTik routers that automatically creates a backup and reverts the router to that backup after a specified time, unless manually deactivated. It’s designed to provide an automatic safety net against configuration errors by creating a restore point and reverting to it after a set period if the router is reset or power-cycled while the script is active. The source originates from this github project: [https://github.com/mikrotik-user/auto-sys-restore].
If you are doing anything remotely risky on RouterOS, you should be using RouterOS Safe-Mode.
There are occasions where SafeMode is not applicable because of the nature of the change. auto-sys-restore was created for. In these situations, install auto-sys-restore script before making any changes in configuration. Once the script is run you have 10 minutes (or your configured time interval) to change critical sections in configuration and confirm they are working as expected. If everything is OK simply disarm restore script by running no-autosys-restore when you are finished. If your changes lock you out of the console for any reason, the system will eventually reboot and restore the configuration to the point in time when the script was invoked.
Download auto-sys-restore.rsc on your mikrotik router /tool fetch url="https://raw.githubusercontent.com/mikrotik-user/auto-sys-restore/main/auto-sys-restore.rsc" mode=https dst-path=auto-sys-restore.rsc. Also you may download file manually and upload it to router.
Import script /import auto-sys-restore.rsc. You may also copy content of this page and paste to a newly created script using GUI. The script is also available from this HamWAN site.
Set restoreTime to any time period you need. Default value is 10m. Either edit the file before importing or use /system script edit.
Now you may run this script via CLI or directly from Winbox GUI.
/system script run auto-sys-restoreTo disarm auto-sys-restore, run no-autosys-restore script that is generated automatically immediatelly after main script was initiated.
/system script run no-autosys-restoreno-autosys-restore script also removes auxiliary scripts automatically generated by main script.
If router is power cycled or reset while this script is running, configuration will be restored anyway by auto-sys-restore-after-reboot (another automatically created script) in 10 minutes after router was started.
The version below has been reformated to make it more readable, but is otherwise identical to the version in github. The githup version is also available from this HamWAN site (download link)
/system script add dont-require-permissions=no name=auto-sys-restore owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
\n # Time in minutes before script restores router configuration\
\n :global restoreTime 10m\
\n\
\n :if ( [ :typeof \"\$restoreTime\" ] != \"time\" ) do={\
\n :log warn ( \"auto-sys-restore: required time value is not specified or has incorrect value. Using default - 10 minutes\" )\
\n :set restoreTime 10m\
\n }\
\n\
\n :local cdate [ /system clock get date ] \
\n :local ctime [ /system clock get time ] \
\n :local bckpFile \"auto-sys-restore-auto\"\
\n\
\n :if ( [ :len [ file find where type=\"disk\" and name=\"flash\" ] ] != 0 ) do={ :set bckpFile \"flash/auto-sys-restore\" }\
\n :do { /system backup save dont-encrypt=yes name=\"\$bckpFile\" } on-error={ :error \"auto-sys-restore: can't create binary backup\" }\
\n\
\n /system scheduler \
\n :do { remove [ find name=\"auto-sys-restore-in-time\" ] } on-error={} \
\n :do { remove [ find name=\"auto-sys-restore-after-reboot\" ] } on-error={}\
\n :do { add comment=\"Auto restore in time period. Generated by auto-sys-restore script\" \\\
\n name=\"auto-sys-restore-in-time\" \\\
\n start-date=\$cdate start-time=[ ( \$ctime + \$restoreTime ) ] \\\
\n on-event=\"/system scheduler remove [ find name=\\\"auto-sys-restore-after-reboot\\\" ] \\r\\n\\\r\
\n /system backup load name=\\\"\$bckpFile.backup\\\" password=\\\"\\\"\" disabled=no } on-error={:error \"Can't create auto-sys-restore-in-time scheduler\"}\
\n :do { add comment=\"Auto restore after reboot. Generated by auto-sys-restore script\"\\\
\n name=\"auto-sys-restore-after-reboot\" \\\
\n start-time=startup \\\
\n on-event=\"/system scheduler remove [ find name=\\\"auto-sys-restore-in-time\\\" ] \\r\\n\\\r\
\n :delay 300 \\r\\n\\\r\
\n /system backup load name=\\\"\$bckpFile.backup\\\" password=\\\"\\\"\" disabled=no } on-error={:error \"Can't create auto-sys-restore-after-reboot scheduler\"}\
\n\
\n :log warn ( \"auto-sys-restore: system backup restore is scheduled in \$restoreTime (file: \$bckpFile.backup)\" )\
\n :log warn ( \"auto-sys-restore: execute script no-autosys-restore to remove scheduled restore event\" )\
\n :put ( \"auto-sys-restore: System backup restore is scheduled in \$restoreTime (file: \$bckpFile.backup)\" )\
\n :put ( \"auto-sys-restore: execute script no-autosys-restore to remove scheduled restore event\" )\
\n /system script\
\n add comment=\"This script will remove scheduled event for rollback system\" dont-require-permissions=no name=no-autosys-restore owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \\\
\n source=\":do { /system scheduler remove [ find name=\\\"auto-sys-restore-in-time\\\" ] } on-error={:error \\\"Can't remove scheduler auto-sys-restore-in-time\\\"} \\\r\
\n \\n:do { /system scheduler remove [ find name=\\\"auto-sys-restore-after-reboot\\\" ] } on-error={:error \\\"Can't remove scheduler auto-sys-restore-after-reboot\\\"}\\\r\
\n \\n:log warn \\\"restore-in-time event has been removed\\\"\\\r\
\n \\n:put \\\"restore-in-time event has been removed\\\"\\\r\
\n \\n:do { /system script remove [ find name=\\\"no-autosys-restore\\\" ]} on-error={}\\\r\
\n \\n:do { /file remove [ find name=\\\"auto-sys-restore-auto.backup\\\" ]} on-error={}\"\
\n\
\n /system script environment remove [ find name=\"restoreTime\" ]"